package com.jt.config;

import com.jt.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfigurer implements WebMvcConfigurer{//web.xml
	@Autowired
	private UserInterceptor userInterceptor;
	/**
	 * 开启匹配后缀型配置
	 * ->开启匹配后,"https://item.jd.com/1041228.html",
	 * 就不会去webapp底下找1041228.html,
	 * 而是把这个路径看成一种请求,1041228可以看做restFul风格里的id
	 * 搜索引擎只能记录到.html结尾的静态网页,为了(增加曝光率)让搜索引擎可以查询到我的商品,所以使用.html而不是用.jsp
	 */
	@Override
	public void configurePathMatch(PathMatchConfigurer configurer) {
		
		configurer.setUseSuffixPatternMatch(true);
	}
	/**
	 * 添加拦截器的配置.当"/cart/**","/order/**"这样的请求来了来了,就要走拦截器,校验是否登录了
	 * 还需要配置拦截器的路径
	 * 		"/*"表示拦截一级
	 * 		"/**"表示拦截多级
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(userInterceptor).addPathPatterns("/cart/**","/order/**");
	}
}
